<template>
    <div>

        <div style="margin: 10px 0">
            <el-input style="width: 200px" placeholder="请输入集卡订单号" suffix-icon="el-icon-search" v-model="truckOrder"></el-input>
            <el-button class="ml-5" type="primary" @click="load">搜索</el-button>
            <el-button type="warning" @click="reset">重置</el-button>
        </div>

        <el-table :data="tableData" border stripe :header-cell-class-name="'headerBg'" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="id" label="ID" width="80"></el-table-column>
            <el-table-column prop="truckOrder" label="集卡订单"></el-table-column>
            <el-table-column prop="shipOrder" label="船舶订单"></el-table-column>
            <el-table-column prop="yard" label="场区号"></el-table-column>
            <el-table-column prop="row" label="贝号"></el-table-column>
            <el-table-column prop="column" label="列号"></el-table-column>
            <el-table-column prop="floor" label="层号"></el-table-column>
        </el-table>
        <div style="padding: 10px 0">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="pageNum"
                    :page-sizes="[5, 10, 20, 50]"
                    :page-size="5"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    import {serverIp, serverPort} from "../config/config";

    export default {
        name: 'Home',
        data() {
            return {
                serverIp: serverIp,
                serverPort: serverPort,
                tableData: [],
                total: 0,
                pageNum: 1,
                pageSize: 5,
                truckOrder: "",
                form: {},
                dialogFormVisible: false,
                multipleSelection: [],
            }
        },
        created() {
            this.load()
        },
        methods: {
            load() {
                this.request.get("/user/container/page",{
                    params: {
                        pageNum: this.pageNum,
                        pageSize: this.pageSize,
                        truckOrder: this.truckOrder,
                        username: JSON.parse(localStorage.getItem("user")).username
                    }
                }).then(res => {
                    this.tableData = res.data.data
                    this.total = res.data.total
                })
            },
            reset() {
                this.yard = ""
                this.load()
            },
            handleSizeChange(pageSize) {
                this.pageSize = pageSize;
                this.load()
            },
            handleCurrentChange(pageNum) {
                this.pageNum = pageNum;
                this.load()
            },
            handleSelectionChange(val) {
                this.multipleSelection = val
            },
            handleAdd() {
                this.form = {}
                this.dialogFormVisible = true
            },
            save() {
                this.request.post("/user/container",this.form).then(res => {
                    if(res.code === '200') {
                        this.$message.success("保存成功")
                        this.dialogFormVisible = false
                        this.load()
                    } else{
                        this.$message.error("保存失败")
                    }
                })
            },
            handleEdit(row) {
                this.form = row
                this.dialogFormVisible = true
            },
            del(id) {
                this.request.get("/user/container/delete?id=" + id).then(res => {
                    if(res.data) {
                        this.$message.success("删除成功")
                        this.load()
                    } else{
                        this.$message.error("删除失败")
                    }
                })
            },
            delBatch() {
                let ids = this.multipleSelection.map(v => v.id)
                this.request.post("/user/container/delete/batch",ids).then(res => {
                    if(res.data) {
                        this.$message.success("删除成功")
                        this.load()
                    } else{
                        this.$message.error("删除失败")
                    }
                })
            }
        }
    }
</script>

<style>
    .headerBg {
        background: #eee!important;
    }
</style>
